// pages/jp_show/jp_show.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    appurl: app.apiurl,
apiimg: app.apiimg,
prize_id:'',
jianglin:'',
beizhu:'',
beizhu1:'',
beizhu2:'',
duihuan:false,
xiaoxi:0,
xiaoxi2:0,
  },
  z_beizhu(e){
    this.setData({
      beizhu:e.detail.value
    })
  },
  z_beizhu1(e){
    this.setData({
      beizhu1:e.detail.value
    })
  },
z_open(){
  this.setData({
    duihuan:true
  })
},
z_close(){
  this.setData({
    duihuan:false
  })
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      　bottomHeight : app.globalData.bottomHeight,
      prize_id:options.id
    })  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.z_jiangpin()
    this.z_yonghu()
    this.xcx_msg_info1()
  },
  xcx_msg_info1() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/totalNoReadNum',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          xiaoxi:res.data.data.total_num
        })
      }
    })
  },
  z_jiangpin(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/prize/detail?prize_id=' + _this.data.prize_id,
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        res.data.data.content = res.data.data.content?.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/ig, 'style="max-width:100%;height:auto;"');    
         _this.setData({
          jianglin:res.data.data
         })
         if(res.data.data.con_type == '2'){
           _this.setData({
             beizhu2:'如奖品有多个第三方应用（app），请写明需充值的第三方应用（app）名称，否则可能无法充值'
           })
         }
      }
    })
  },
  z_yonghu(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/myInfo',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
       if(res.data.code == '1001'){
         _this.setData({
           login:true,
           yonghu:res.data.data
         })
       }
      }
    })
  },
  z_duihuan(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
      "prize_id":_this.data.prize_id,
      "xnczzh":_this.data.beizhu1,
      "lj_remark":_this.data.beizhu,
      "name":_this.data.yonghu.shr_name,
      "tel":_this.data.yonghu.shr_tel,
      "address":_this.data.yonghu.yj_addr
    }
    wx.request({
      url: app.apiurl + 'api/prize/dhPrize',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        wx.showToast({
          title: res.data.msg,
          icon: 'none',
          duration: 2000
        })
        _this.setData({
          duihuan:false
        })
      }
    })
  },
  z_duihuan111(){
    let _this = this
    let xnczzh = _this.data.beizhu1
    let params = {
      "token":wx.getStorageSync("user_token"),
      "prize_id":_this.data.prize_id,
      "xnczzh":xnczzh,
      "lj_remark":_this.data.beizhu,
      "name":_this.data.yonghu.shr_name,
      "tel":_this.data.yonghu.shr_tel,
      "address":_this.data.yonghu.yj_addr
    }
    if(xnczzh == ''){
      wx.showToast({
        title: '请输入充值账号',
        icon: 'none',
        duration: 2000
      })
    } else {
      wx.request({
        url: app.apiurl + 'api/prize/dhPrize',
        method: 'POST',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
          _this.setData({
            duihuan:false
          })
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})